package com.example.cloud.service.business.medical.impl;

import com.example.cloud.dao.business.medical.SpecialRecordsRepository;
import com.example.cloud.model.business.medical.SpecialRecords;
import com.example.cloud.service.business.medical.SpecialRecordsService;
import com.example.cloud.utils.BusinessUtil;
import com.example.cloud.utils.RequestUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

/**
 * Created by wangtao on 2018/6/6.
 */
@Service
public class SpecialRecordsServiceImpl implements SpecialRecordsService {

    private static final Logger logger = Logger.getLogger(SpecialRecordsServiceImpl.class);

    @PersistenceContext
    EntityManager em;

    @Autowired
    private SpecialRecordsRepository specialRecordsRepository;

    @Override
    public SpecialRecords findOne(Long id) {
        return specialRecordsRepository.findOne(id);
    }

    @Override
    public List<SpecialRecords> findByPatientId(Long patientId) {
        return specialRecordsRepository.findByPatientIdAndDeleteFlag(patientId,0);
    }

    @Override
    @Transactional
    public void doSave(SpecialRecords record) {
        record.setAccountId(RequestUtil.getLoginUser().getAccountId());
        BusinessUtil.appendRecord(record);
        specialRecordsRepository.save(record);
    }

    @Override
    @Transactional
    public void doDelete(List<Long> ids) {
        specialRecordsRepository.deleteByIdIn(ids);
    }
}
